﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Kugar.Core.Communications
{
    public class TransferStopedException:Exception
    {
        public TransferStopedException() : base("连接已停止")
        {
        }
    }

    public class TransferClosedException : Exception
    {
        public TransferClosedException()
            : base("连接已关闭")
        {
        }
    }

    public class TransferException : Exception
    {
        public TransferException(Exception innerError)
            : base("传输错误",innerError)
        {
        }

        public TransferException(string message) : base(message, null){}
    }

    public class TransferReceivingException:Exception
    {
        private static TransferReceivingException _defaultValue=new TransferReceivingException();

        public TransferReceivingException():base("该链接正在接收,无法再开始接收"){}

        
    }

    public class TransferConnectException:Exception
    {
        public TransferConnectException(string error):base(string.Format("连接失败 " + error))
        {
            
        }
    }

    public class TransferDisconnectedException : Exception
    {
        public TransferDisconnectedException()
            : base("连接已断开")
        {
        }
    }

    public static class TransferExceptionHelper
    {
        private static TransferStopedException _transferStoped=new TransferStopedException();
        private static TransferClosedException _transferClosed = new TransferClosedException();
        private static TransferReceivingException _transferReceiving = new TransferReceivingException();
        private static TransferDisconnectedException _transferDisconnected = new TransferDisconnectedException();


        public static void ThrowTransferClosedException()
        {
            throw _transferClosed;
        }

        public static void ThrowTransferStopedException()
        {
            throw _transferStoped;
        }

        public static void ThrowTransferReceivingException()
        {
            throw _transferReceiving;
        }

        public static void ThrowTransferDisconnectedException()
        {
            throw _transferDisconnected;
        }

        public static void ThrowTransferException(string message)
        {
            throw new TransferException(message);
        }

        public static void ThrowTransferException(Exception innerException)
        {
            throw new TransferException(innerException);
        }

        public static void ThrowTransferConnectException(string message)
        {
            throw new TransferConnectException(message);
        }


        public static Exception GetTransferClosedException()
        {
            return _transferClosed;
        }

        public static Exception GetTransferStopedException()
        {
            return _transferStoped;
        }

        public static Exception GetTransferReceivingException()
        {
            return _transferReceiving;
        }

        public static Exception GetTransferDisconnectedException()
        {
            return _transferDisconnected;
        }

        public static Exception GetTransferException(string message)
        {
            return new TransferException(message);
        }

        public static Exception GetTransferException(Exception innerException)
        {
            return new TransferException(innerException);
        }

        public static Exception GetTransferConnectException(string message)
        {
            return new TransferConnectException(message);
        }
    }
}
